#delimit ;
set logtype text;
log using ~/directional/replicate.sta, replace;
set more off;
set memory 10m;
use direct1204.dta;
note: conditions 1 Miller moderate, Cook conservative, 2 Miller
liberal, Cook moderate, 3 Miller moderate, Cook moderate, 4 Miller
liberal, Cook conservative; 

note: c1-c8 no recode needed.  Valid responses of 1-7;

note: polatt no recode needed.  Valid responses of 1-4;
note: vote02 no recode needed.  Valid responses of 1-2;
note: create the subject's party id scores;
gen partyid=0 if strdem==1;
replace partyid=1 if strdem==2;
replace partyid=6 if strrep==1;
replace partyid=5 if strrep==2;
replace partyid=4 if indep==1;
replace partyid=2 if indep==2;
replace partyid=3 if indep==3;

note: create the subject's ideological placement;
gen ideology=1 if strlib==1;
replace ideology=2 if strlib==2;
replace ideology=3 if strlib==3;
replace ideology=9 if strcon==1;
replace ideology=8 if strcon==2;
replace ideology=7 if strcon==3;
replace ideology=4 if strmod==1;
replace ideology=6 if strmod==2;
replace ideology=5 if strmod==3;

note: coding for directional-type issue measures;

*Guns;
gen guns=.;
replace guns=-3 if sguns==1 & ssguns==1;
replace guns=-2 if sguns==1 & ssguns==2;
replace guns=-1 if sguns==1 & ssguns==3;
replace guns=3 if sguns==2 & ssguns==1;
replace guns=2 if sguns==2 & ssguns==2;
replace guns=1 if sguns==2 & ssguns==3;
gen gunsd=(guns>0);

*Econ;
gen econ=.;
replace econ=-3 if secon==1 & ssecon==1;
replace econ=-2 if secon==1 & ssecon==2;
replace econ=-1 if secon==1 & ssecon==3;
replace econ=3 if secon==2 & ssecon==1;
replace econ=2 if secon==2 & ssecon==2;
replace econ=1 if secon==2 & ssecon==3;
gen econd=(econ>0);

*Drugs;
gen drugs=-3 if sdrugs==1 & ssdrugs==1;
replace drugs=-2 if sdrugs==1 & ssdrugs==2;
replace drugs=-1 if sdrugs==1 & ssdrugs==3;
replace drugs=3 if sdrugs==2 & ssdrugs==1;
replace drugs=2 if sdrugs==2 & ssdrugs==2;
replace drugs=1 if sdrugs==2 & ssdrugs==3;
gen drugsd=(drugs>0);

*Health;
gen rhealth=rheatl;
gen health=-3 if shealth==1 & sshealt==1;
replace health=-2 if shealth==1 & sshealt==2;
replace health=-1 if shealth==1 & sshealt==3;
replace health=3 if shealth==2 & sshealt==1;
replace health=2 if shealth==2 & sshealt==2;
replace health=1 if shealth==2 & sshealt==3;
gen healthd=(health>0);

*Abortion;
note: these issues have the low value as the conservative position;
gen abor=3 if sabort==1 & ssabort==1;
replace abor=2 if sabort==1 & ssabort==2;
replace abor=1 if sabort==1 & ssabort==3;
replace abor=-3 if sabort==2 & ssabort==1;
replace abor=-2 if sabort==2 & ssabort==2;
replace abor=-1 if sabort==2 & ssabort==3;
gen abord=(abor>0);

*Environment;
gen envir=3 if senvir==1 & ssenvir==1;
replace envir=2 if senvir==1 & ssenvir==2;
replace envir=1 if senvir==1 & ssenvir==3;
replace envir=-3 if senvir==2 & ssenvir==1;
replace envir=-2 if senvir==2 & ssenvir==2;
replace envir=-1 if senvir==2 & ssenvir==3;
gen envird=(envir>0);

*Education;
gen educ=3 if seduc==1 & sseduc==1;
replace educ=2 if seduc==1 & sseduc==2;
replace educ=1 if seduc==1 & sseduc==3;
replace educ=-3 if seduc==2 & sseduc==1;
replace educ=-2 if seduc==2 & sseduc==2;
replace educ=-1 if seduc==2 & sseduc==3;
gen educd=(educ>0);

*Iraq;
gen iraq=3 if siraq==1 & ssiraq==1;
replace iraq=2 if siraq==1 & ssiraq==2;
replace iraq=1 if siraq==1 & ssiraq==3;
replace iraq=-3 if siraq==2 & ssiraq==1;
replace iraq=-2 if siraq==2 & ssiraq==2;
replace iraq=-1 if siraq==2 & ssiraq==3;
gen iraqd=(iraq>0);

note: obtain general measure of subjects' directional beliefs;
gen sdirsum=(guns+econ+drugs+health+abor+envir+educ+iraq)/8;

note: change names of the thermometer scores;
gen demtherm=thermd;
gen reptherm=thermr;
drop thermd thermr;

note: create vote variable;
gen repvote=1 if vote1==1 | vote2==2;
replace repvote=0 if vote1==2 | vote2==1;
gen demvote=(repvote==0);

note: ideological placements of the candidates;
gen rideol=1 if rstrlib==1;
replace rideol=2 if rstrlib==2;
replace rideol=3 if rstrlib==3;
replace rideol=9 if rstrcon==1;
replace rideol=8 if rstrcon==2;
replace rideol=7 if rstrcon==3;
replace rideol=4 if rsltmod==1;
replace rideol=6 if rsltmod==2;
replace rideol=5 if rsltmod==3;
gen dideol=1 if dstrlib==1;
replace dideol=2 if dstrlib==2;
replace dideol=3 if dstrlib==3;
replace dideol=9 if dstrcon==1;
replace dideol=8 if dstrcon==2;
replace dideol=7 if dstrcon==3;
replace dideol=4 if dsltmod==1;
replace dideol=6 if dsltmod==2;
replace dideol=5 if dsltmod==3;

note: coding for directional-type issue questions follows that from
above with the exception that the dxxx, sdxxx, rxxx, srxxx; 
note: coding for directional-type issue measures;
note: recode for the Republican candidate;
gen repguns=-3 if rguns==1 & srguns==1;
replace repguns=-2 if rguns==1 & srguns==2;
replace repguns=-1 if rguns==1 & srguns==3;
replace repguns=3 if rguns==2 & srguns==1;
replace repguns=2 if rguns==2 & srguns==2;
replace repguns=1 if rguns==2 & srguns==3;
gen repecon=-3 if recon==1 & srecon==1;
replace repecon=-2 if recon==1 & srecon==2;
replace repecon=-1 if recon==1 & srecon==3;
replace repecon=3 if recon==2 & srecon==1;
replace repecon=2 if recon==2 & srecon==2;
replace repecon=1 if recon==2 & srecon==3;
gen repdrugs=-3 if rdrugs==1 & srdrugs==1;
replace repdrugs=-2 if rdrugs==1 & srdrugs==2;
replace repdrugs=-1 if rdrugs==1 & srdrugs==3;
replace repdrugs=3 if rdrugs==2 & srdrugs==1;
replace repdrugs=2 if rdrugs==2 & srdrugs==2;
replace repdrugs=1 if rdrugs==2 & srdrugs==3;
gen repheal=-3 if rhealth==1 & srhealt==1;
replace repheal=-2 if rhealth==1 & srhealt==2;
replace repheal=-1 if rhealth==1 & srhealt==3;
replace repheal=3 if rhealth==2 & srhealt==1;
replace repheal=2 if rhealth==2 & srhealt==2;
replace repheal=1 if rhealth==2 & srhealt==3;
note: these issues have the low value as the conservative position;
gen repabor=3 if rabort==1 & srabort==1;
replace repabor=2 if rabort==1 & srabort==2;
replace repabor=1 if rabort==1 & srabort==3;
replace repabor=-3 if rabort==2 & srabort==1;
replace repabor=-2 if rabort==2 & srabort==2;
replace repabor=-1 if rabort==2 & srabort==3;
gen repenvir=3 if renvir==1 & srenvir==1;
replace repenvir=2 if renvir==1 & srenvir==2;
replace repenvir=1 if renvir==1 & srenvir==3;
replace repenvir=-3 if renvir==2 & srenvir==1;
replace repenvir=-2 if renvir==2 & srenvir==2;
replace repenvir=-1 if renvir==2 & srenvir==3;
gen repeduc=3 if reduc==1 & sreduc==1;
replace repeduc=2 if reduc==1 & sreduc==2;
replace repeduc=1 if reduc==1 & sreduc==3;
replace repeduc=-3 if reduc==2 & sreduc==1;
replace repeduc=-2 if reduc==2 & sreduc==2;
replace repeduc=-1 if reduc==2 & sreduc==3;
gen repiraq=3 if riraq==1 & sriraq==1;
replace repiraq=2 if riraq==1 & sriraq==2;
replace repiraq=1 if riraq==1 & sriraq==3;
replace repiraq=-3 if riraq==2 & sriraq==1;
replace repiraq=-2 if riraq==2 & sriraq==2;
replace repiraq=-1 if riraq==2 & sriraq==3;
note: recodes for the Democratic candidate;
gen demguns=-3 if dguns==1 & sdguns==1;
replace demguns=-2 if dguns==1 & sdguns==2;
replace demguns=-1 if dguns==1 & sdguns==3;
replace demguns=3 if dguns==2 & sdguns==1;
replace demguns=2 if dguns==2 & sdguns==2;
replace demguns=1 if dguns==2 & sdguns==3;
gen demecon=-3 if decon==1 & sdecon==1;
replace demecon=-2 if decon==1 & sdecon==2;
replace demecon=-1 if decon==1 & sdecon==3;
replace demecon=3 if decon==2 & sdecon==1;
replace demecon=2 if decon==2 & sdecon==2;
replace demecon=1 if decon==2 & sdecon==3;
gen demdrugs=-3 if ddrugs==1 & sddrugs==1;
replace demdrugs=-2 if ddrugs==1 & sddrugs==2;
replace demdrugs=-1 if ddrugs==1 & sddrugs==3;
replace demdrugs=3 if ddrugs==2 & sddrugs==1;
replace demdrugs=2 if ddrugs==2 & sddrugs==2;
replace demdrugs=1 if ddrugs==2 & sddrugs==3;
gen demheal=-3 if dhealth==1 & sdhealt==1;
replace demheal=-2 if dhealth==1 & sdhealt==2;
replace demheal=-1 if dhealth==1 & sdhealt==3;
replace demheal=3 if dhealth==2 & sdhealt==1;
replace demheal=2 if dhealth==2 & sdhealt==2;
replace demheal=1 if dhealth==2 & sdhealt==3;

note: these issues have the low value as the conservative position;
gen demabor=3 if dabort==1 & sdabort==1;
replace demabor=2 if dabort==1 & sdabort==2;
replace demabor=1 if dabort==1 & sdabort==3;
replace demabor=-3 if dabort==2 & sdabort==1;
replace demabor=-2 if dabort==2 & sdabort==2;
replace demabor=-1 if dabort==2 & sdabort==3;
gen demenvir=3 if denvir==1 & sdenvir==1;
replace demenvir=2 if denvir==1 & sdenvir==2;
replace demenvir=1 if denvir==1 & sdenvir==3;
replace demenvir=-3 if denvir==2 & sdenvir==1;
replace demenvir=-2 if denvir==2 & sdenvir==2;
replace demenvir=-1 if denvir==2 & sdenvir==3;
gen demeduc=3 if deduc==1 & sdeduc==1;
replace demeduc=2 if deduc==1 & sdeduc==2;
replace demeduc=1 if deduc==1 & sdeduc==3;
replace demeduc=-3 if deduc==2 & sdeduc==1;
replace demeduc=-2 if deduc==2 & sdeduc==2;
replace demeduc=-1 if deduc==2 & sdeduc==3;
gen demiraq=3 if diraq==1 & sdiraq==1;
replace demiraq=2 if diraq==1 & sdiraq==2;
replace demiraq=1 if diraq==1 & sdiraq==3;
replace demiraq=-3 if diraq==2 & sdiraq==1;
replace demiraq=-2 if diraq==2 & sdiraq==2;
replace demiraq=-1 if diraq==2 & sdiraq==3;

note: create variable measuring correct recall of candidate's party;
gen idparty=2-recr1 if recr1==1;
replace idparty=2-recd2 if recd2==1;
replace idparty=recr2-1 if recr2==2;
replace idparty=recd1-1 if recd1==2;
replace idparty=0 if idparty>1;

note: create variable for candidate ideology;
gen demlib=0 if cond==1 | cond==3;
replace demlib=1 if cond==2 | cond==4;
gen repcon=0 if cond==2 | cond==3;
replace repcon=1 if cond==1 | cond==4;

note: divided respondents by side of continuum;
gen lib=(sdirsum<0);
gen con=(sdirsum>0 & sdirsum<=3);

note: create summary directional measure for each candidate;
gen ddirsum=(demguns+demecon+demdrugs+demheal+demabor+demenvir+demeduc+demiraq)/8;  
gen rdirsum=(repguns+repecon+repdrugs+repheal+repabor+repenvir +repeduc+repiraq)/8;

note: create dependent variable for vote;
gen samevote=1 if repvote==1 & sdirsum>0;
replace samevote=1 if repvote==0 & sdirsum<0;
replace samevote=0 if repvote==1 & sdirsum<0;
replace samevote=0 if repvote==0 & sdirsum>0;

note: create dependent variable for themometer difference;
gen repdiff=reptherm-demtherm;
gen demdiff=demtherm-reptherm;

gen extrcond=(repcon==1) if sdirsum>0;
replace extrcond=(demlib==1) if sdirsum<0;
gen sametherm=reptherm if sdirsum>0;
replace sametherm=demtherm if sdirsum<0;
gen samediff=repdiff if sdirsum>0;
replace samediff=demdiff if sdirsum<0;
gen extvote=1-((sdirsum>=-1.25 & sdirsum<0) | (sdirsum>0 &
sdirsum<=1.0)) if sdirsum!=0; 
gen xextvote=extrcond*extvote;
gen sameparty=partyid if sdirsum>0;
replace sameparty=6-partyid if sdirsum<0;

*TABLE 2;
note: calculate the 95% confidence ints for the candidate placements;
reg dideol if demlib==1;
reg dideol if demlib==0;
reg ideology;
reg rideol if repcon==0;
reg rideol if repcon==1;
reg ddirsum if demlib==1;
reg ddirsum if demlib==0;
reg sdirsum;
reg rdirsum if repcon==0;
reg rdirsum if repcon==1;
reg demguns if demlib==1;
reg demguns if demlib==0;
reg guns;
reg repguns if repcon==0;
reg repguns if repcon==1;
reg demecon if demlib==1;
reg demecon if demlib==0;
reg econ;
reg repecon if repcon==0;
reg repecon if repcon==1;
reg demdrugs if demlib==1;
reg demdrugs if demlib==0;
reg drugs;
reg repdrugs if repcon==0;
reg repdrugs if repcon==1;
reg demheal if demlib==1;
reg demheal if demlib==0;
reg health;
reg repheal if repcon==0;
reg repheal if repcon==1;
reg demabor if demlib==1;
reg demabor if demlib==0;
reg abor;
reg repabor if repcon==0;
reg repabor if repcon==1;
reg demenvir if demlib==1;
reg demenvir if demlib==0;
reg envir;
reg repenvir if repcon==0;
reg repenvir if repcon==1;
reg demeduc if demlib==1;
reg demeduc if demlib==0;
reg educ;
reg repeduc if repcon==0;
reg repeduc if repcon==1;
reg demiraq if demlib==1;
reg demiraq if demlib==0;
reg iraq;
reg repiraq if repcon==0;
reg repiraq if repcon==1;

*TABLE 4: Column 1 (All voters, Therm difference);
reg samediff extrcond extvote xextvote sameparty;

*TABLE 4: Column 2 (All voters, Vote);
probit samevote extrcond extvote xextvote sameparty;

*TABLE 4: Column 3 (Voters who locate candidates correctly, Therm Difference);
reg samediff extrcond extvote xextvote sameparty if dideol<5 &
rideol>5 & idparty==1; 

*TABLE 4: Column 4 (Voters who locate candidates correctly, Vote);
probit samevote extrcond extvote xextvote sameparty if dideol<5 &
rideol>5 & idparty==1; 

*TABLE 5 (All Voters);
reg sametherm extrcond extvote xextvote sameparty;

*TABLE 5 (Voters who locate candidates correctly);
reg sametherm extrcond extvote xextvote sameparty if dideol<5 &
rideol>5 & idparty==1; 

log close;
